<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="公告标题">
          <a-input placeholder="请输入公告标题" v-decorator="['remark1', validatorRules.remark1]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          :required="true"
          label="轮播图">
          <!--<a-input placeholder="请输入图片" v-decorator="['banner', {}]" />-->
          <j-image-upload text="上传" v-model="banner" ></j-image-upload>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="排序">
          <a-input-number placeholder="请输入排序" v-decorator="['indexP', validatorRules.indexP]" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          :required="true"
          label="公告详情">
          <a-row :gutter="24">
            <a-col :span="24">
              <a-form-item style="min-height: 300px">
                <j-editor v-model="remark2" ></j-editor>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form-item>
        <!--<a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="0:正常,1:删除">
          <a-input placeholder="请输入0:正常,1:删除" v-decorator="['delflag', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark">
          <a-input placeholder="请输入remark" v-decorator="['remark', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark1">
          <a-input placeholder="请输入remark1" v-decorator="['remark1', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark3">
          <a-input placeholder="请输入remark3" v-decorator="['remark3', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark4">
          <a-input placeholder="请输入remark4" v-decorator="['remark4', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark5">
          <a-input placeholder="请输入remark5" v-decorator="['remark5', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark6">
          <a-input placeholder="请输入remark6" v-decorator="['remark6', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark7">
          <a-input placeholder="请输入remark7" v-decorator="['remark7', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark8">
          <a-input placeholder="请输入remark8" v-decorator="['remark8', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark9">
          <a-input placeholder="请输入remark9" v-decorator="['remark9', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark10">
          <a-input placeholder="请输入remark10" v-decorator="['remark10', {}]" />
        </a-form-item>-->

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
  import JImageUpload from '@/components/jeecg/JImageUpload'
  import JEditor from '@/components/jeecg/JEditor'

  export default {
    name: "GBannerModal",
    components: { JEditor,JImageUpload},
    data () {
      return {
        banner:[],
        remark2:'',
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
          indexP:{rules: [{ required: true, message: '请输入排序!' }]},
          remark1:{rules: [{ required: true, message: '请输入公告标题!' }]},
        },
        url: {
          add: "/gbanner/gBanner/add",
          edit: "/gbanner/gBanner/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.remark2 = record.remark2;
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'banner','indexP','delflag','remark','remark1','remark2','remark3','remark4','remark5','remark6','remark7','remark8','remark9','remark10'))
          this.banner = record.banner;
		  //时间格式化
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        if(this.banner =="" || this.banner == null){
          this.$message.warning("请上传轮播图！");
          return false;
        }
        if (this.remark2 == undefined || this.remark2 == '') {
          this.$message.warning('请输入公告详情！')
          return false
        };
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            formData.banner = this.banner;
            formData.remark2 = this.remark2;
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>